home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 6.1 KB | 196 lines | [TEXT/MPS ] |
- ;=============================================================================
- ; Object Pascal Library Routines
- ;
- ; Copyright © 1984-1990 Apple Computer, Inc. All rights reserved.
- ;
- ; NOTE:
- ; The optimizer redirects the following procedure name
- ;
- ;%_METHOD becomes %_JMPTOTRAP
- ;
-
- Blanks On
- String AsIs
- Case On
-
- Print Off
- Include 'Macros.a'
- Include 'Traps.a'
-
- LOAD 'ProgStrucMacs.d'
- LOAD 'FlowCtlMacs.d'
- Print On
-
- ;---------------------------------------------------------------------------------------------------
- ; tests testClass for being a member of the superClass
- ; uses A0,A1,D0,D1
-
- Seg 'MAObjectRes'
- EXPORT FUNCTION ISCLASSIDMEMBERCLASS(testClassID:W, superClassID:W):B
- BEGIN
- import PSUPERCLASSTABLE:DATA
- Move.W superClassID(FP),D0 ; D0 := Test Class Number
- Beq.S isFALSE ; Exit with FALSE if Test Class is NIL
- Move.W testClassID(FP),D1 ; D1 := object Class number
- Beq.S isFALSE ; Exit with FALSE if Test Class is NIL
-
- Move.L PSUPERCLASSTABLE(A5),A0 ; A0 := Superclass Table Handle
- Move.L (A0),A0 ; A0 := Superclass Table Pointer
-
- Cmp.W (A0),D0 ; make sure class ID is in range
- Bge.S isFALSE
- Cmp.W (A0),D1 ; make sure class ID is in range
- Bge.S isFALSE
- INOB1
- Cmp.W D1,D0 ; Compare object's (or superclass') number against
- ; Test Class'
- Beq.S isTRUE ; Exit with TRUE if we get a match
- Move.W (A0,D1.W),D1 ; D1 := Superclass of D1
- Beq.S isFALSE ; Zero means no superclass, so function returns false
- Bra.S INOB1
-
- isTRUE Move.B #1,ISCLASSIDMEMBERCLASS(FP) ; Set return value to TRUE
- Bra.S GoBack
-
- isFALSE Clr.B ISCLASSIDMEMBERCLASS(FP) ; Set return value to FALSE
- GoBack
- Return
- EndFunc
-
-
- ;---------------------------------------------------------------------------------------------------
-
- Seg 'MAObjectRes'
- EXPORT PROCEDURE Dummy
- BEGIN
- _Debugger
-
- Return ; should never be reached
- ENDP
-
- ;---------------------------------------------------------------------------------------------------
-
- Seg '%_MethTables'
- EXPORT PROCEDURE %_JMPTOTRAP
- BEGIN x ; suppress the LINK instruction
- import Dummy
- Jmp Dummy
-
- Return ; should never be reached
- ENDP
-
- ;---------------------------------------------------------------------------------------------------
-
- ; Stack locations
- SelectorTableAddr equ 0
- ActualReturnAddr equ SelectorTableAddr + 4
- RcvrHandleAddr equ ActualReturnAddr + 4
-
- ;---------------------------------------------------------------------------------------------------
-
- If qDebug Then
- Seg '%_MethTables'
- EXPORT PROCEDURE %_DISCIPLINEDISPATCH
- BEGIN x ; suppress the LINK instruction
- import FAILNONOBJECT, Dummy, PDISCIPLINEMETHODCALLS:DATA
- Tst.B PDISCIPLINEMETHODCALLS(A5)
- BZ.S %_DISCIPLINEDISPATCH_PATCHPOINT
- Move.L RcvrHandleAddr(SP), -(SP) ;receiver handle for FailNonObject
- JSR FAILNONOBJECT
-
- Export %_DISCIPLINEDISPATCH_PATCHPOINT
- %_DISCIPLINEDISPATCH_PATCHPOINT:
- Jmp Dummy ; now dispatch
-
- Return ; should never be reached
- ENDP
- EndIf
-
-
- ;---------------------------------------------------------------------------------------------------
- ; PROCEDURE MethodDispatch ( 'uses nonstandard stack params ' );
- ; (SP) = selector table address (first return address on stack)
- ; 4(SP) = actual return address (selector proc caller's return address)
- ; 8(SP) = receiver (the object being dispatched for)
-
- ; Uses only scratch registers: A0/A1/D0/D1/D2. A5 must be correct.
-
- ; Selector Proc Format
- ; --------------------
- ; JSR %_JmpToTrap
- ; Selector Table
- ; --------------
- ; Number of repeating entries - 1
- ; Cached ClassID
- ; Cached Implementation address (A5 JT relative (16 bit))
- ; Repeating Entries
- ; -----------------
- ; ClassID
- ; Implementation address (A5 JT relative (16 bit))
- ; .
- ; .
- ;
-
- ; Table locations
- NumberOfEntries equ 0
- CacheClassID equ NumberOfEntries + 2
- CacheImplementation equ CacheClassID + 2
- FirstClassID equ CacheImplementation + 2
- FirstImplementation equ FirstClassID + 2
-
- SizeOfEntry equ 4
-
- Seg '%_MethTables'
- EXPORT PROCEDURE %_NEWMETHOD
- BEGIN x, ; suppress the link instruction
- import PSUPERCLASSTABLE:DATA
- import PDISPATCHERRORPROC:DATA
- Move.L RcvrHandleAddr(SP),A1 ; A1 := receiver handle
- Move.L (A1),A1 ; A1 := receiver ptr
- Move.W (A1),D0 ; D0 := receiver's ClassID
-
- Move.L (SP)+,A0 ; A0 := Method table ptr
- ; immediately follows selector
- Move.W (A0)+,D1 ; D1 := number of implementations of method (-1)
- Cmp.W (A0)+,D0 ; cached ClassID versus receiver ClassID
- Bne.S search ; Not Equal => must search table
- Move.W (A0),A1 ; A1 := A5 relative offset to method
- CacheOut Jmp (A5,A1.W) ; via Jump Table
- search
- Move.W D0,-(A0) ; cache the ClassID
- Move.L A0,D2 ; D2 := ptr to ClassID cache
- loopa
- AddQ.L #SizeOfEntry,A0 ; A0 := ptr to next ClassID in table
- Cmp.W (A0),D0 ; next ClassID versus given ClassID
- DBcc D1,loopa ; fall through if (A0) unsigned <= D0
- Beq.S found ; Eq => found it
- Move.L PSUPERCLASSTABLE(A5),A1 ; A1 := handle to Superclass table
- Move.L (A1),A1 ; A1 := ptr to Superclass table
- Bra.S doSuper ; Get Superclass
- loopb
- AddQ.L #SizeOfEntry,A0 ; A0 := ptr to next ClassID in table
- loop2
- Cmp.W (A0),D0 ; next ClassID versus given ClassID
- DBcc D1,loopb ; fall through if (A0) unsigned <= D0
- Beq.S found ; Eq => found it
- doSuper
- Move.W 0(A1,D0.W),D0 ; D0 := SuperClassID of D0 (D0 is always even!)
- Bne.S loop2 ; Not Equal => still worth searching
-
- ; Error condition: method not found
- Move.L D2,A1 ; A1 := ptr to ClassID cache
- Clr.L (A1)
- Move.L PDISPATCHERRORPROC(A5),A1 ; ptr to error routine
- ErrorOut Jmp (A1)
-
- found
- Move.L D2,A1 ; A1 := ptr to ClassID cache
- Move.W 2(A0),A0 ; A0 := A5 relative offset to method
- Move.W A0,2(A1) ; stow Implementation in cache
- TableOut Jmp (A5,A0.W) ; via Jump Table
-
- Return ; should never be reached
-
- End
-
-